﻿using System;
using Microsoft.Xna.Framework.Content;
using ProjetCom.Model.Competences;
using ProjetCom.Vue;
using System.IO;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Xml;


namespace ProjetCom.Ctrl
{
    class CtrlCompetence : CtrlTemplate
    {
        private CategorieList m_categorie;

        public String CategorieLabel
        {
            get
            {
                return m_categorie.Label;
            }
        }

        public List<String> Text
        {
            get
            {
                List<String> listeCompetence = new List<String>();

                foreach (Categorie categorie in m_categorie)
                {
                    String strCompetence = categorie.Label + "\n";

                    foreach (Competance competence in categorie)
                        {
                            strCompetence += "    " + competence.Name + ": ";

                            if (Score >= competence.Price)
                            {
                                String lastCompetance = competence.Values[competence.Values.Count - 1];

                                foreach (String comp in competence.Values)
                                {
                                    strCompetence += comp;
                                    if (lastCompetance != comp)
                                    {
                                        strCompetence += ", ";
                                    }
                                    if (lastCompetance == comp)
                                    {
                                        strCompetence += ".\n";
                                    }
                                }
                            }
                            else
                            {
                                strCompetence += "Vous devez avoir " + competence.Price + " points. Il vous en manque " + (competence.Price - Score) + ".\n";
                            }
                        }
                    strCompetence += "\n";

                    listeCompetence.Add(strCompetence);
                }

                return listeCompetence;
            }
        }

        public CtrlCompetence(IServiceProvider p_serviceProvider, int p_score, String p_idComp) : base(p_serviceProvider, p_score) {
            ContentManager content = new ContentManager(p_serviceProvider, "Content");
            StreamReader streamReader = new StreamReader(Path.Combine("Content/CompetencesXML/Competences.xml"));
            XDocument xmlDoc = XDocument.Load(streamReader);

            m_categorie = new CategorieList(xmlDoc, p_idComp);
            m_Level = new LevelCompetence(p_serviceProvider, this);
        }
        public override void Update(Microsoft.Xna.Framework.GameTime _gameTime)
        {
        }

        public override void EventClavier()
        {
        }
    }
}
